Method and apparatus for rapid processing of scene-based programs

ABSTRACT

A system and method for rapid processing of scene-graph-based data and/or programs is disclosed. In one embodiment, the system may be configured to utilize a scene graph directly. In another embodiment, the system may be configured to generate a plurality of structures and thread that manage the data originally received as part of the scene graph. The structures and threads may be configured to convey information about state changes through the use of messaging. The system may include support for messaging between threads, messaging with time and/or event stamps, epochs to ensure consistency, and ancillary structures such as render-bins, geometry structures, and rendering environment structures.

CROSS REFERENCE TO RELATED APPLICATIONS

This application claims the benefit of U.S. Provisional Application No.60/156,054, filed on Sep. 24, 1999 and No. 60/175,580, filed on Jan. 11,2000.

BACKGROUND OF THE INVENTION

1. Field of the Invention

This invention relates generally to the field of computer graphics and,more particularly, to graphics systems and software that manage andrender three-dimensional graphics data.

2. Description of the Related Art

A computer system typically relies upon its graphics system forproducing visual output on the computer screen or display device. Earlygraphics systems were only responsible for taking what the processorproduced as output and displaying it on the screen. In essence, theyacted as simple translators or interfaces. Modern graphics systems,however, incorporate graphics processors with a great deal of processingpower. They now act more like coprocessors rather than simpletranslators. This change is due to the recent increase in both thecomplexity and amount of data being sent to the display device. Forexample, modern computer displays have many more pixels, greater colordepth, and are able to display more complex images with higher refreshrates than earlier models. Similarly, the images displayed are now morecomplex and may involve advanced techniques such as anti-aliasing andtexture mapping.

As a result, without considerable processing power in the graphicssystem, the CPU would spend a great deal of time performing graphicscalculations. This could rob the computer system of the processing powerneeded for performing other tasks associated with program execution andthereby dramatically reduce overall system performance. With a powerfulgraphics system, however, when the CPU is instructed to draw a box onthe screen, the CPU is freed from having to compute the position andcolor of each pixel. Instead, the CPU may send a request to the videocard stating “draw a box at these coordinates.” The graphics system thendraws the box, freeing the processor to perform other tasks.

Generally, a graphics system in a computer (also referred to as agraphics system) is a type of video adapter that contains its ownprocessor to boost performance levels. These processors are specializedfor computing graphical transformations, so they tend to achieve betterresults than the general-purpose CPU used by the computer system. Inaddition, they free up the computer's CPU to execute other commandswhile the graphics system is handling graphics computations. Thepopularity of graphical applications, and especially multimediaapplications, has made high performance graphics systems a commonfeature of computer systems. Most computer manufacturers now bundle ahigh performance graphics system with their systems.

Since graphics systems typically perform only a limited set offunctions, they may be customized and therefore far more efficient atgraphics operations than the computer's general-purpose centralprocessor. While early graphics systems were limited to performingtwo-dimensional (2D) graphics, their functionality has increased tosupport three-dimensional (3D) wire-frame graphics, 3D solids, and nowincludes support for three-dimensional (3D) graphics with textures andspecial effects such as advanced shading, fogging, alpha-blending, andspecular highlighting.

To take advantage of the new capabilities of both graphics systems andmodern CPUs in general, graphics application program interfaces (“APIs”)have been developed. An API is a set of routines, protocols, and/ortools for building software applications. An API attempts to simplifythe task of developing a program by providing building blocks needed byprogrammers to create their application. One example of a popular API isMicrosoft Corporation's Win32 API.

While graphics API have been successful in allowing programmers torapidly develop graphical applications, the recent increase in thecomplexity of the scenes being rendered is placing ever greater demandson the CPUs and graphics systems that are executing the applications.Traditionally, when tasks become too computationally intensive for asingle CPU, multiple CPU systems are used. These multiple CPU systemsutilize parallel processing to divide the computations among two or moreprocessors. However, typical graphics APIs are not well suited to allowparallel processing, particularly over a network. Thus, a system andmethod for efficiently managing the creation, updating, and rendering ofa complex scene is needed. In particular, a system and method capable ofbeing implemented in an API and capable of supporting distributedprocessing in a networked setting is also desired.

SUMMARY OF THE INVENTION

The problems identified above may at least in part be solved by a systemand method for rapid processing of scene graph-based data as descriedherein. In one embodiment, the system generates a parallel structure forthe scene graph-based data. The parallel structure may include bothobjects and threads. Advantageously, the system may utilize a parallelstructure for rendering and thereby avoid repeated traversals of thescene graph in its hierarchy (i.e., tree) form. This parallel structuremay be implemented in an API such that it is effectively unseen bygraphics application programmers, who continue to use the scene graphstructure to create graphics applications.

In one embodiment, the system may be configured to utilize a scene graphdirectly. In another embodiment, the system may be configured to utilizea scene graph as a source for ancillary structures. The ancillarystructures may aid the system in rendering and executing thescene-graph-based program. The system may also include support formessaging between threads and objects, messaging with time and/or eventstamps, epochs to ensure consistency, and ancillary structures such asrender-bins, geometry structures, and rendering environment structures.

A computer program is also contemplated. In one embodiment, the computerprogram comprises a plurality of instructions configured to receive ascene graph and traverse the scene graph to generate a plurality ofstructures and threads corresponding to the scene graph. The scene graphmay include information representing a plurality of three-dimensionalobjects. The scene graph may also include a number of different types ofdata, including, behavior data for the three-dimensional objects, sounddata, haptic data (e.g., force-feed back data) appearance data, geometrydata, environmental data (e.g., lighting, fog), and other data. Theinformation may include appearance data, geometry data, andenvironmental data. Each structure may be an object that managesselected data from the scene graph, and the plurality of threads may beexecutable to render one or more frames corresponding to the scenegraph. In some embodiments the threads may be configured to generatemessages to specify state changes, and the messages can be multicast tomultiple structures or unicast to a single structure. Each structure mayhave a corresponding update thread configured to update the structure.

One of the parallel structures created is preferably a render bin thatis configured to receive and store references to particular geometrydata that is to be rendered in the render bin. The render bin may haveone or more render threads associated with it, thereby enabling parallelrendering utilizing multiple processors.

Advantageously, each structure may be configured to manage (andoptionally optimize) its own data. Thus one structure may manage alltransform data, and may optimize multiple transforms by collapsing themtogether.

As noted above, a method for managing and rendering a scene graph isalso contemplated. In one embodiment, the method may include generatinga scene graph, wherein the scene graph comprises informationrepresenting a plurality of three-dimensional objects; and traversingthe scene graph to generate a parallel set of structures and threadscorresponding to the scene graphs, wherein each structure comprises anobject that manages selected data from the scene graph, and wherein theplurality of threads are executable to render one or more framescorresponding to the scene graph. The method may be implemented insoftware, hardware, or a combination thereof.

BRIEF DESCRIPTION OF THE DRAWINGS

The foregoing, as well as other objects, features, and advantages ofthis invention may be more completely understood by reference to thefollowing detailed description when read together with the accompanyingdrawings in which:

FIG. 1 illustrates one embodiment of a computer system that may be usedto implement the system and method described herein;

FIG. 2 is a simplified block diagram of the computer system of FIG. 1;

FIG. 3 is a diagram illustrating one embodiment of a scene graph;

FIG. 4 is a diagram illustrating one embodiment of a scene graph withparallel structures of managing and rendering;

FIG. 5 is a flowchart of one embodiment of a method for generating theparallel structure of FIG. 4;

FIG. 6 is a diagram of another embodiment of a scene graph;

FIG. 7 is a diagram of one embodiment of structure optimization;

FIG. 8 is a diagram of one embodiment of a list of current work threads;

FIG. 9 is a diagram illustrating a number of example configurations forscreen and canvas lists.

While the invention is susceptible to various modifications andalternative forms, specific embodiments thereof are shown by way ofexample in the drawings and will herein be described in detail. Itshould be understood, however, that the drawings and detaileddescription thereto are not intended to limit the invention to theparticular form disclosed, but on the contrary, the intention is tocover all modifications, equivalents, and alternatives falling withinthe spirit and scope of the present invention as defined by the appendedclaims. The word “may” is used in this application in a permissive sense(i.e., having the potential to, being able to), not a mandatory sense(i.e., must). Similarly, the word include, and derivations thereof, areused herein to mean “including, but not limited to.”

DETAILED DESCRIPTION OF SEVERAL EMBODIMENTS

Computer System—FIG. 1

Referring now to FIG. 1, one embodiment of a computer system 10 that mayused to implement the system and method described above is illustrated.The computer system may be used as the basis for any number of varioussystems, including a traditional desktop personal computer, a laptopcomputer, a network PC, an Internet appliance, a television, includingHDTV systems and interactive television systems, personal digitalassistants (PDAs), and other device which displays 2D and or 3Dgraphics.

As shown in the figure, computer system 10 comprises a system unit 12and a video monitor or display device 14 coupled to the system unit 12.The display device 14 may be any of various types of display monitors ordevices (e.g., a CRT, LCD, or gas-plasma display). Various input devicesmay be connected to the computer system, including a keyboard 16 and/ora mouse 18, or other input device (e.g., a trackball, digitizer, tablet,six-degree of freedom input device, head tracker, eye tracker, dataglove, body sensors, etc.). Application software may be executed by thecomputer system 10 to display 3D graphical objects on display device 14.The application software may be stored in memory, read from a serverusing a network connection, or read from a storage medium such as acomputer diskette, CD-ROM, DVD-ROM, or computer tape.

Computer System Block Diagram—FIG. 2

Referring now to FIG. 2, a simplified block diagram illustrating oneembodiment of the computer system of FIG. 1 is shown. Elements of thecomputer system that are not necessary for an understanding of thepresent invention are not shown for convenience. As shown, the computersystem 10 includes a central processing unit (CPU) 22 coupled to ahigh-speed memory bus or system bus 24. A system memory 26 may also becoupled to high-speed bus 24.

Host processor 22 may comprise one or more processors of varying types,e.g., microprocessors, multi-processors and CPUs. The system memory 26may comprise any combination of different types of memory subsystems,including random access memories, (e.g., static random access memoriesor “SRAMs”, synchronous dynamic random access memories or “SDRAMs”, andRambus dynamic access memories or “RDRAM”, among others) and massstorage devices. The system bus or host bus 24 may comprise one or morecommunication or host computer buses (for communication between hostprocessors, CPUs, and memory subsystems) as well as specializedsubsystem buses.

A 3D graphics system or graphics system 28 according to the presentinvention is coupled to the high-speed memory bus 24. The 3D graphicssystem 28 may be coupled to bus 24 by, for example, a crossbar switch orother bus connectivity logic. It is assumed that various otherperipheral devices, or other buses, may be connected to the high-speedmemory bus 24. It is noted that the 3D graphics system may be coupled toone or more of the buses in computer system 10 and/or may be coupled tovarious types of buses. In addition, the 3D graphics system may becoupled to a communication port and thereby directly receive graphicsdata from an external source, e.g., the Internet or a network. As shownin the figure, display device 14 is connected to the 3D graphics system28 comprised in the computer system 10.

Host CPU 22 may transfer information to and from the graphics system 28according to a programmed input/output (I/O) protocol over host bus 24.Alternately, graphics system 28 may access the memory subsystem 26according to a direct memory access (DMA) protocol or throughintelligent bus mastering.

A graphics application program conforming to an application programminginterface (API) such as OpenGL or Java 3D may execute on host CPU 22 andgenerate commands and data that define a geometric primitive (graphicsdata) such as a polygon for output on display device 14. As defined bythe particular graphics interface used, these primitives may haveseparate color properties for the front and back surfaces. Hostprocessor 22 may transfer these graphics data to memory subsystem 26.Thereafter, the host processor 22 may operate to transfer the graphicsdata to the graphics system 28 over the host bus 24. In anotherembodiment, the graphics system 28 may read in geometry data arrays overthe host bus 24 using DMA access cycles. In yet another embodiment, thegraphics system 28 may be coupled to the system memory 26 through adirect port, such as the Advanced Graphics Port (AGP) promulgated byIntel Corporation.

The graphics system may receive graphics data from any of varioussources, including the host CPU 22 and/or the system memory 26, othermemory, or from an external source such as a network, e.g., theInternet, or from a broadcast medium, e.g., television, or from othersources.

One embodiment of a graphics system may comprise a graphics processorcoupled to a display buffer. As used herein, a display buffer is abuffer that stores information (e.g., pixels or samples that may be usedto form pixels) that represents a particular frame to be output anddisplayed on a display device. For example, a traditional frame buffermay be considered to be a display buffer. The contents of the displaybuffer are typically output to digital to analog converters (DACs) thatconvert the digital information into analog video signals for display ona display device. Depending upon the configuration, the graphicsprocessor (or processors, in the case of a parallel processing system)is configured to execute instructions and/or process data received frommain system memory and/or the host CPU.

Computer system 10 may also include a network interface (not shown) toallow the computer system to send and receive data from a computernetwork. In one embodiment, the computer system may be configured todistribute tasks associated with the management and rendering of athree-dimensional scene graph to other computers on the network. Thetasks may be distributed by sending objects (e.g., data and threads) toother computers on the network (i.e., each utilizing its own non-sharedmemory). The computers may communicate with each other via a system ofmessages (as explained in greater detail below).

Scene Graph—FIG. 3

As noted above, scene graphs are hierarchies of objects and graphicsdata that define a particular three-dimensional scene or world. Forexample, the top node may represent an entire building and all thefurnishings and people that occupy the building. As the scene graph istraversed, the next level of group nodes may represent particular roomswithin the building. Traversing the scene graph one more level may yieldgroup nodes that each represent one person or furniture object (e.g., achair) in a particular room. Each group node may also have transformnode that translates and/or rotates any nodes below the transform node(i.e., child nodes). While many levels of the scene graph are possible,eventually a traversal of the scene graph will terminate at a leaf node.Leaf nodes typically represent a certain object (e.g., a tea cup or achair) or a portion of a larger object (e.g., a person's hand). The leafnode typically has one or more pointers to graphics data that describethe object. For example, in embodiment the leaf node may have pointersto a data file that includes polygons (or NURBS—Non-Uniform RationalB-Splines) defining the shape of the object and texture maps that definethe appearance of the object. The leaf node may also have pointers to abounding box.

Before the scene graph is submitted for rendering, it is advantageous toperform “object culling”. Object culling refers to the process ofselectively removing objects from the scene graph. In mostimplementations of object culling, objects are removed either becausethey are outside the current view frustum, or because they are occluded(either partially or fully). Object culling is particularly useful forcomplex scene graphs that have a large number of objects. Since currentgraphics hardware may be unable to achieve satisfactory frame rates whenrendering all of the objects, object culling attempts to remove theobjects that cannot be seen from the current viewpoint/orientation. Thusobject culling attempts to reduce wasting graphics pipeline bandwidth byrendering only those objects that are actually visible to the viewer.For example, assuming that a particular scene graph represents a virtualmodel of an entire city, if the current viewpoint is close to the baseof a particular building, that particular building will obscure thosebehind it. Thus, assuming that the building is opaque and that noshadows or reflections of other structures behind the particularbuilding are visible, then there is no reason to devote renderingresources to rendering those obscured structures.

Turning now to FIG. 3, one embodiment of a scene graph 50 is shown. Inthis example, scene graph 50 is created from instances of Java 3Dclasses, but other types of scene graphs are also possible andcontemplated (e.g., VRML scene graphs). Scene graph 50 is assembled fromobjects that define the geometry, sound, lights, location, orientation,and appearance of visual and audio objects.

As illustrated in the figure, scene graph 50 may be thought of as a datastructure having nodes and arcs. A node represents a data element, andan arc represents the relationship between data elements. In the figure,all nodes of scene graph 50 are the instances of Java 3D classes. Thearcs represent two types of relationships between the Java 3D classinstances. The first type of relationship is a parent-childrelationship. For example, in this embodiment a group node such asbranch group node 60 can have any number of children (such as Shape3Dleaf node 64), but only one parent (i.e., local node 54). Similarly, aleaf node has one parent but no children. These relationships areindicated in the figure by solid lines. The second type of relationshipis a reference. A reference associates a particular node componentobject with a scene graph node. Node component objects define thegeometry and appearance attributes used to render the visual objects.References are indicated in the figure by dashed lines.

As shown in the figure, Java 3D™ scene graph 50 is constructed of nodeobjects in parent-child relationships forming a tree structure. In atree structure, one node (e.g., VirtualUniverse node 52 in the figure)is the root. Other nodes are accessible by following arcs from the root.Scene graph 50 is formed from the trees rooted at locale object 54. Thenode components and reference arcs are not part of the scene graph tree.Since only one path exists from the root of a tree to each of theleaves, there is only one path from the root of a scene:graph to eachleaf node. The path from the root of scene graph 50 to a specific leafnode is called the leaf node's “scene graph path.” Since a scene graphpath leads to exactly one leaf, there is one scene graph path for eachleaf in the scene graph 50.

Each scene graph path in a Java 3D scene graph completely specifies thestate information of its leaf. State information includes the location,orientation, and size of a visual object. Consequently, the visualattributes of each visual object depend only on its scene graph path.The Java 3D renderer takes advantage of this fact and renders the leavesin the order it determines to be most efficient. The Java 3D programmernormally does not have control over the rendering order of objects.

Graphic representations of a scene graph can serve as design tool and/ordocumentation for Java 3D programs. Scene graphs are drawn usingstandard graphic symbols as shown in the figure. Java 3D programs mayhave many more objects than those of the scene graph.

To design a Java 3D virtual universe, a scene graph is drawn using thestandard set of symbols. After the design is complete, that scene graphdrawing may be used as the specification for the program. After theprogram is complete, the same scene graph is a concise representation ofthe program (assuming the specification was followed). Thus, a scenegraph drawn from an existing program documents the scene graph theprogram creates.

Rapid Processing of Scene Graph-Based Programs

First, a general overview of one embodiment of a system and method forscene graph-based programs is disclosed. Then, a more detailedexplanation of one embodiment of the system and method implementedwithin the context of a Java 3D API is disclosed. As one skilled in theart will appreciate after reviewing this disclosure, the accompanyingfigures, and the attached claims, other programming languages and/orAPIs may be utilized or modified to implement the system and methoddisclosed herein.

As noted above, to improve the flexibility and/or speed of processingscene-based programs, a graphics system (hardware and/or software) maybe configured to use a scene graph directly or as a “source” structurefor building various ancillary structures. A detailed description andexample of the use of a scene graph is attached hereto in Attachment 2(“Getting Started with the Java 3D™ API”). In one embodiment thegraphics system may be configured to use those ancillary structures toeither (i) aid in rendering and executing a scene-graph-based program,e.g., one that includes rendering (including frustum culling andocclusion culling), sound (including mono, stereo, and spatializedsounds), execution culling, collision detection, and/or picking, moreefficiently; or (ii) aid in generating ancillary structures for directexecution with limited or no reference to the original scene graph(compilation).

This may include, but need not be limited to, the use of ancillarystructures to reduce the extent of traversal of the original structure,replacement of the original structure by one or more ancillarystructures thereby reducing references to the original structure (scenegraph), or even the complete replacement of the original structure bynew structures containing sufficient information to render and executethe associated scene-graph-based program (including but not limited tographics, behavior, sound, collision detection, and picking).

One particular implementation of such an ancillary structure (designedfor scalability) is a lower dimensional version of k-dop hierarchy, inthis case a hierarchy of axis-aligned bounding-boxes (6-dops) for use invisibility detection, frustum culling, occlusion culling, executionculling, collision detection, bounding volume determination, andpicking. One such embodiment is disclosed in U.S. patent applicationSer. No. 09/247,466, filed on Feb. 9, 1999, entitled “Visible ObjectDetermination for Interactive Visualization.”

In some embodiments, the system may support a system-based scheduler,called master control, that handles management of various resourcesincluding the resources of single and multi-processor systems. Mastercontrol may manage the various renderers and system computations andallocates their execution to a computer's various processors, memorysystems, and even other network-attached computers. Master control canserialize the system's various computations or to execute thosecomputations in parallel. It can allow adding or removing rendering andcomputational components both at initial startup time or dynamicallyover time as the system continues to execute. This orthogonalization ofthe various rendering and computational components allows extending thescene-graph-execution system with new renderers (such as haptic rendersfor touch or force feedback devices) or replacing an existing rendererwith a different implementation of that renderer.

In some embodiments, the system may also implement the use of messagepassing for specifying state changes. These messages are labeled with amonotonic increasing time-/event-stamp. These “stamped” or labeledevents allow concurrent or distributed processing while ensuringconsistency.

In some embodiments, the system may be configured to use “epochs” toensure consistency. An epoch consists of all messages having compact(continuous) set of labels (time-/event-stamps) that fall within anselected interval of “stamped” messages. The continuous declaration of anew epoch allows renderers and other computations to work within thecurrent epoch and thus work with a consistent set of changes.

In some embodiments, an ancillary structure called the geometrystructure may be used. The geometry structure may be configured tocontain the current consistent state of all spatially-located renderableobjects. The structure may be a bounding-box hierarchy that uses acluster algorithm for grouping renderable, spatially-located, objects.It may also include specialized method for rapidly including andexcluding larger number of objects (switch processing). It may furtherinclude specialized methods for re-balancing the hierarchy to retaindesirable properties. It permits consistent and concurrent access to itsobjects.

An ancillary structure called the rendering-environment structurecontains the current consistent state of all non-renderable spatiallylocated objects (including non-geometric objects such as lights, fog,background, clip, model-clip, etc. nodes). It shares the specializedmethod for rapidly including and excluding objects and for re-balancingthe hierarchy to retain desirable properties. It permits consistent andconcurrent access to its objects.

In some embodiments, the graphics system may be configured ogenerate/support an ancillary structure called a render-bin. A renderbin may be configured to contain a superset of the objects that need tobe rendered for a particular frame. The render bin may “age” objectsheld within the structure and remove “over-age” objects duringoccasional “compaction” computations. The render-bin structure may beMT/MP (multithread/multiprocessor) enabled, thereby allowing concurrentaccess both for adding objects and for access to objects. The structuremay both sort objects to be rendered into an order more compatible withthe underlying rendering hardware architecture and for other local(almost “peephole”) optimization that allow renderable components tocombine or split for more appropriate matching to the underlyinghardware. The renderable objects, held within the render bin, can haveassociated callbacks that will execute before the associated object isrendered, and they can hold references to multiple state change objects.They can also contain system specific computations including multipletransform matrices, rendering attributes, and levels of geometricdetail, or user-specified computation versions of each of the previous.The render-bin structure may be optimized to include or exclude largegroups of renderable objects (switch mode processing).

Turning now to FIG. 4, a diagram illustrating one embodiment of a methodfor creating a parallel structure for managing and rendering scenegraphs is shown. The scene graph (FIGS. 3 and 4) comprises locale node54, transform nodes 66A-D, view platform 74, light node 90, behaviornode 92, Shape3D node 64, appearance node, component 70 and geometrynode component 72. Note that the figure only illustrates a portion ofthe scene graph and that additional nodes and node components (e.g.,BranchGroup nodes) are present but not shown in the figure forsimplicity.

As shown in the figure, as the scene graph is created or initiallytraversed, a parallel configuration comprising a number of structures200-210 is generated. each structure is responsible for a particulartype of object in the scene graph. For example. geometry structure 200is responsible for the geometry node components of the scene graph.Similarly, rendering attribute structure 202 is responsible forrendering attributes such as the current viewpoint and view frustum.Rendering environment structure 204 is responsible for lighting andother environmental effects such as fog. Transform structure 206 isresponsible for transformation group nodes, and behavior structure 208is responsible for behavior nodes (e.g., changes to objects as theresult of certain conditions being met, such as a collision beingdetected). Render bin 210 is responsible for the selecting and renderingobjects.

As shown in the figure, the parallel data structures 200-208 may eachhave an update thread 200B-208B. The update threads may be invoked(e.g., based on messages in the corresponding message queue) to processchanges. For example, assuming the color of the light node 90 changes, amessage to that effect may be sent to rendering environment structure204's message queue 204A. The rendering environment structure's updatethread 204B may be invoked to check the message queue 204A for messages,detect the update message, and change the rendering environmentstructure 204 accordingly. In some cases, the update thread may generateits own messages that are conveyed to other structures (e.g., to renderbin 210).

Render bin 210 may be configured with a number of different renderthreads 212A-212N in lieu of an update thread. These threads may operatein parallel and render different portions of the render bin 210. Oneexample of this is a system utilizing a head-mounted display for virtualreality. Head mounted displays typically have two screens (one for eacheye). To achieve a visible stereo effect, each display typicallydisplays a different image, each rendered according to a differentviewpoint. Thus, a different render thread may be started for each ofthe two different displays. Similarly, in some virtual realityapplications, multiple users may each have their own viewpoint as theyindividually navigate the virtual world. In another embodiment, adifferent render bin is generated for each viewpoint (this described ingreater detail below). The render threads may still operate in parallel,but may each correspond to a particular object or objects instead of aparticular view.

Note, while a number of different types of parallel data structures areshown in the figure and described herein, additional types of paralleldata structures may be created as necessary (e.g., for sound or forcefeedback device support), depending upon the exact implementation.Similarly, a number of additional threads may also be created.

Advantageously, by using this parallel structure the scene graph need betraversed only once to generate the parallel structures. By reducing thenumber of scene graph traversals, rendering performance may potentiallybe improved. Furthermore, different portions of the parallel structuresand their corresponding threads may be conveyed across a network toanother computer for parallel processing (i.e., to one or morenon-shared memory computers). Once each structure is set up, executionmay occur in parallel, with state change information being conveyed viamessages transmitted between the different computers or processors. Incontrast, continually repeating traversals of the scene graph does notlend itself as well to a parallel processing implementation, particularwhen the parallel processors do not share memory.

Each structure 200-210 has a corresponding message queue 200A-210A thatis configured to receive and store messages. As shown in the figure,during the creation or initial traversal of the scene graph, messagesmay be generated and conveyed to the corresponding parallel structures.For example, when geometry node component 72 is added to the scenegraph, a message is sent to geometry structure 200's message queue 200A.Similarly, when light node 90 is added to the scene graph, a message issent to rendering environment structure 204's message queue 204B.

Turning now to FIG. 5, a flowchart of one embodiment of a method forcreating parallel structures for managing and rendering scenegraph-based graphics data is shown. In this embodiment, the methodbegins (step 100) with the creation of a universe (step 102). Next,children nodes (e.g. as shown in FIGS. 3 and 4) and branch graphs arecreated (step 104). This process continues until the tree is complete(step 106). Next, the tree is traversed (step 110). For each nodedetected (step 112), a message (e.g., “InsertNode”) is generated (step114). Similarly, for each new view detected (step 116), created amessage (e.g., “CreateRenderBin”) is generated (step 118). This processcontinues until the tree has been completely traversed (step 120). Note,in other embodiments the messages may be generated concurrently with thecreation of the scene graph tree.

Next, a time counter may be initialized (step 122), and the mastercontrol thread may be started (step 130). The master control thread isconfigured to define the current epoch (step 132), and then schedulethreads for execution (step 134). This process continues until executionis complete (steps 136-138). An epoch is a time period defined by themaster control thread to allow for efficient scheduling of threadexecution. Messages may be timestamped, thereby allowing the mastercontrol thread to schedule threads based on the age (and importance) ofthe messages or tasks to be processed by the threads. One embodiment ofthis time management process is described in greater detail below.

Example Embodiment Using Java 3D™ API

Java 3D Architecture

The Java 3D API may be used to implement one embodiment of the systemand method described above. One such implementation is described indetail below. However, it is noted that other implementations are alsopossible and contemplated. To describe this particular embodiment, anoverview of the Scene Graph Structure will be presented, and thencomponents of a runtime system will be presented. Next, the process ofsystem startup, runtime system operation, and system shutdown arepresented. Then, specific features of this embodiment are explained ingreater detail. Also note, that standard Java™ and Java 3D variablenames, object names, and processes are used herein. For more informationon Java and Java 3D, the reader is directed to the books titled “TheJava 3D™ API Specification,” by Sowizral, Rushforth, and Deering,published by Addison-Wesley Publishing Co., ISBN: 0201710412, and “TheJava™ Programming Language” by Ken Arnold, James Gosling, David Holmes,published by Addison-Wesley Publishing Co., ISBN: 0201704331.

Scene Graph Structure

The Java 3D API is a set of Java classes. Applications create instancesof these classes and invoke their methods to control Java 3D. In oneimplementation, many of these classes may be merely wrapper classesaround retained classes that actually handle the implementation. When anAPI object is created, that object may create its retained counterpart.This is true for all classes that are subclasses of Node andNodeComponent. In one embodiment, the working scene graph structure isimplemented on the retained side alone.

Turning now to FIG. 6, one embodiment of the scene graph structure isshown. In this embodiment, the scene graph structure and all thechild/parent relationships are implemented in the retained classes. TheAPI classes may be configured as wrapper classes ([54], 62, 66A, 66B,64A, 64B) around the retained classes (62′, 66A′, 66B′, 64A′, and 64B′).In addition, all scene graph links (e.g., parent/child relationships)are implemented on the retained side. In some embodiments most of eachclass may be implemented on the retained side. As also shown in thefigure, in this embodiment the “Locale” class has no parallel retainedclass. One possible advantage of using this type of internal structureis that capability bit processing and scene graph compilation aresimplified (as described in greater detail below).

Capability Bit Processing

Capability bits may be used in the Java 3D API by applications to informJava 3D what modifications or queries the application will make todifferent parts of the scene graph. Each Node and NodeComponent in thescene graph may have capability bits defined for that Node orNodeComponent. After a branch graph has been made live (inserted intothe scene graph) or compiled (via BranchGroup.compile( ) orSharedGroup.compile( )), the application may only modify or make queriesbased on the capability bits that it has set for each object. This maybe implemented by having the methods in each of the API classesresponsible for checking capability bits before calling the parallelretained method.

The following code is an example of such a test from the Material class:

public final void setAmbientColor(Color3f color){

if (isLiveOrCompiled( ))

if (!this.capabilities.get(ALLOW_COMPONENT_WRITE))

throw new CapabilityNotSetException(“Material: no capability

to set component”);

((MaterialRetained)this.retained).setAmbientColor(color);

}

The Material.ALLOW_COMPONENT_WRITE capability bit is the one defined tocontrol the setting of the material attribute. Some methods have beendefined to not be modifiable once the Object has become compiled orlive. The following code is an example from ImageComponent2D:

public final void set(BufferedImage image) {

checkForLiveOrCompiled( );

((ImageComponent2DRetained)this.retained).set(image);

In this case, the checkForLiveOrCompiled( ) will throw an exception ifthe component is live or compiled. In some embodiments, all Nodes andNodeComponents may enforce capability bit processing. Therefore, allNodes and NodeComponents have parallel retained classes. As changes aremade to the API, Nodes and NodeComponents may be given new features thatmay require new capability bits. To facilitate this while at the sametime trying to maintain a compact overall set (i.e., so that thecapability bit test can be performed quickly), there is a class may beincluded that defines all the capability bit values. This class mayassign the bit values in linear order based on the class hierarchy.Advantageously, any path in the class hierarchy may have bit valuesprogressing in linear order. In addition, independent hierarchies canhave the same bit values, thereby providing a compact set of bit values.

In Java 3D, the deepest class hierarchy is the ConeSound hierarchy, witha maximum capability bit value of 39. Some implementations may set alimit or goal of less than 64 bits (i.e., the number of bits availablein a “long” variable type).

Compiling Branch Graphs

The Java 3D API allows applications to compile a BranchGraph orSharedGraph (via BranchGroup.compile( ) and SharedGroup.compile( )). Atcompile time, the implementation may analyze the subgraph and performoptimizations on the subgraph. The implementation may use the capabilitybits that the application has set to guide the optimizations. An exampleof one possible optimization is to flatten the scene graph.

Turning now to FIG. 7, one embodiment of a method for flattening a scenegraph is illustrated. The figure illustrates two features. First, inthis example the TransformGroup Nodes 66A-B have no capability bits set,so they may not be modified or queried. As a result, when the branchgraph was compiled, the TransformGroupRetained Nodes were eliminatedwith their composite value cached in the Shape3DRetained node 64”.

Second, one possible advantage of configuring the API classes as wrapperclasses around the retained classes is shown. Since the TransformGroupnodes have no capability bits set and this branch has been compiled,there is no way for the application to modify or query theTransformGroupRetained nodes. Thus, they can be eliminated. Theapplication still may have references to the TransformGroup nodes, butsince no capability bits are set, they do not matter.

Thus, the figure illustrates one example of compilation optimization. Ingeneral, however, compilation optimizations are independent fromoptimizations in the rest of the Java 3D implementation. In someembodiments, the optimizations may be performed before the Java 3Druntime system ever receives or processes the subgraph. Other compileoptimizations may include clustering small Shape3D nodes, splittinglarge Shape3D nodes, stripifying geometry data, and even compressinggeometry data.

Runtime System Overview

The Java 3D API is configured to support a multithreaded fullyasynchronous implementation. The API also allows an implementation touse either the Scene Graph as its working structure, or alternate datastructures to improve performance. In some embodiments, the Scene Graphis the main working structure. For many features, this is a usefulworking structure. However, when possible optimizations are considered,the scene graph may actually be a limiting structure to work with. Thus,in other embodiments a more flexible architecture may be supported toprovide for greater optimizations. In one embodiment, the more flexiblearchitecture includes three components: structures, threads, andmessages. Each of these components is described in greater detail below.

Structures

A structure is an object that manages a collection of other objects.Structures are only dependent on the contents of the Scene Graph. Theyare responsible for optimizing the objects that they contain, given theset of requirements on that structure. They are independent of the scenegraph structure and are only responsible for their own objects. Theparent class of all structures is J3dStructure. Listed below aredescriptions for the different types of structures that may be supportedin one embodiment of the system.

GeometryStructure

The GeometryStructure is responsible for organizing all geometry andbounds data in the scene graph. There is one GeometryStructure perVirtualUniverse.

BehaviorStructure

The BehaviorStructure is responsible for organizing all Behavior nodes.It is not responsible for implementing behavior scheduler semantics. Itonly organizes the nodes and their wakeup criteria for fast executionculling and processing. There is one BehaviorStructure per VirtualUniverse.

SoundStructure

The SoundStructure is responsible for organizing all Sound nodes. It isnot responsible for implementing sound scheduler semantics. It onlyorganizes the nodes for fast sound render culling. There is oneSoundStructure per VirtualUniverse.

RenderingEnvironmentStructure

The RenderingEnvironmentStructure is responsible for organizing objectsthat effect the rendering environment. This includes Light, Fog, Clip,Background, and ModelClip nodes. It does not implement their semantics.It only provides fast methods for determining the environmentcharacteristics that apply to a scene or particular geometry. There isone RenderingEnvironmentStructure per VirtualUniverse . . . 1.3.1.5

RenderingAttributesStructure

The RenderingAttributesStructure is responsible for managing allrendering NodeComponent objects and their mirror objects. There is oneRenderingAttributesStructure for all of Java 3D.

RenderBin

The RenderBin structure is responsible for organizing the collection ofvisible geometry objects optimally for rendering. There is one RenderBinper View.

TransformStructure

The TransformStructure is responsible for updating all transforms andbounds used within the system.

Threads

Threads are configured to use the structures described above. There aremany different types of threads in the 1.2 implementation. This sectionpresents all the thread types in the system.

MasterControl

MasterControl is the controlling thread for the system. It doesscheduling for all other threads in the system. It is also responsiblefor taking time snapshots. This will be covered in the Time section.There is one MasterControl for the entire system.

J3dThread

J3dThread is the abstract parent class for all other threads in thesystem. It implements all the functionality for initializing, beingnotified by MasterControl, and cleanup for the threads. All threads inthe system, aside from MasterControl, are a subclass of J3dThread.

StructureUpdateThread

Every structure has a StructureUpdateThread. When messages are sent to astructure, the StructureUpdateThread is scheduled to retrieve thosemessages for its structure. It only retrieves messages for the structurethat fall between the time interval for that update pass. This isdescribed in greater detail below.

Renderer

This is the thread that renders the geometry. It also issues theSwapBuffers command. There is one Renderer per Screen3D. When there aremultiple Canvas3Ds on a single screen, the Renderer thread is run foreach Canvas3D. The Renderer uses the RenderBin and theRenderingAttributesStructure.

BehaviorScheduler

This thread is responsible for scheduling and processing activebehaviors that have triggered. It uses the BehaviorStructure. There iscurrently one BehaviorScheduler per Virtual Universe.

SoundScheduler

This thread is responsible for sound scheduling and sending soundrendering requests to the AudioDevice3D. There is one SoundScheduler perView. It uses the SoundStructure.

InputDeviceScheduler

This thread is responsible for scheduling non-blocking input devices.There is one InputDeviceScheduler per PhysicalEnvironment.

Messages

Messages are used to communicate any change that happens in the system,internal or external, through the system. In one embodiment, a singlemessage class is implemented called “J3dMessage”. Each message may havethe following fields:

time—The time when the message was sent. This is filled in byMasterControl, who is the keeper of time.

refcount—The reference count of this message. A message could go tomultiple destinations. When all destinations consume the message, itsrefcount goes to 0, and the message gets put on the freelist.

threads—A bitmask representing all thread types that need this message.

universe—The universe where this message originated.

view—The View that should receive this message. If it is null, all Viewsget the message.

type—The type of this message.

args—An array of 5 object references. Arguments are passed to thedestinations through this field.

MasterControl keeps a freelist of messages, so when a message is needed,GC activity is reduced.

Time

As used herein, references to time do not refer to the time measured inSystem.currentTimeMillis( ). Instead, it is more accurately called thechange count. MasterControl has a field called “time” that starts out as0, and is incremented (i) each time a message is sent into the system,and (ii) when MasterControl takes a time snapshot. This concept of timeis used to ensure that the various threads are performing their tasks ondata snapshots that are consistent across all threads. This is describedin greater detail below (see section heading MasterControl).

System Startup

Bootstrapping Java 3D includes performing some system-related operationsin order to prepare the system for processing. In one embodiment, thisprocess only occurs once per invocation of the Java 3D system. Thebootstrapping code is contained in MasterControl. MasterControl is astatic member of the VirtualUniverse class, which means that only oneMasterControl will exist in the Java 3D system. Therefore, theconstructor for MasterControl is used to execute bootstrapping code. Forexample, the type of native graphics library to be used may be queried,and then loaded.

The class that contains the native rendering API to use is calledNativeAPIInfo. A different implementation of this class may be compiledfor each different target platform. This class has one method,getRenderingAPI( ), and its possible values are RENDER_OPENGL_SOLARIS,RENDER_OPENGL_WIN32, or RENDER_DIRECT3D. Note, however, that theselection of which rendering library to use may be compiled into thesystem or it may be made runtime selectable by expanding thebootstrapping process.

Applications may be configured to create Java 3D objects in any order.However, there may also be conditions that cause Java 3D to bootstrapitself. First, as seen above, if a VirtualUniverse is created,bootstrapping will occur. There are other cases, like Canvas3D, wherenative library access is needed before a VirtualUniverse is created. Inthese cases, a static initializer method may be included in the class.That method may be configured to call the static methodVirtualUniverse.loadLibraries( ), which will cause the staticMasterControl to get created, and bootstrapping will occur.

Universe Structures

A number of the structures are created when a VirtualUniverse iscreated. These include the GeometryStructure, BehaviorStructure,SoundStructure, and RenderingEnvironmentStructure. They are created herebecause they are View/Rendering independent. They need to be availablewhen Nodes are added to the scene graph, even though a view may not beactive yet. The RenderingAttributesStructure is created whenMasterControl is created because there is only one for all of Java 3D.

Canvas3D Creation

To create a Canvas3D, applications must first get aGraphicsConfiguration that meets their needs. This involves filling outa GraphicsConfigTemplate3D object and passing that object to thegetBestConfiguration( ) method on the device to be rendered. In thecurrent implementation only the default screen device is supported.GraphicsDevice.getBestConfiguration( ) simple calls theGraphicsConfigTemplate3D.getBestConfiguration( ) method passing allavailable configurations as its argument. It is then the responsibilityof the GraphicsConfigTemplate3D class to select the bestGraphicsConfiguration for that template and return it.GraphicsConfigTemplate3D is a Java 3D class, so it has control over theselection process. In GraphicsConfigTemplate3D, there is a class,NativeConfigTemplate3D, that is built into Java 3D at compile time whichimplements the platform/rendering API specific selection semantics. ForSolaris, where OpenGL is the only rendering API, the list ofGraphicsConfigurations passed in is ignored, and the selection isperformed in native code by doing a glXChooseVisual( ). Once the visualis selected, its id is passed back and matched with theGraphicsConfigurations passed in. The GraphicsConfiguration that matchesis returned. On win32, for both OpenGL and Direct3D, the selectionprocess does nothing. The PixelFormat for a win32 window may be changedat any time, so Java 3D simply changes the PixelFormat of the windowwhen the first rendering GraphicsContext is needed by the system. Thiswill be covered more when the Renderer is covered.

At the end of this, the Canvas3D is capable of being rendered into withthe current rendering API. However, the system does not start up untilthe Canvas3D is ready to be rendered into, or activated. This process isdescribed below.

View Activation

The runtime system is started in two steps. The first one is triggeredby a Canvas3D object being added to an AWT (abstract window toolkit)container (i.e., when Canvas3D.addNotify( ) is called). In response, thecanvas notifies its View that it has been added by callingView.addNotify( ). At this point, the View registers itself and theprovoking canvas with MasterControl. Next, the Views RenderBin andSoundScheduler are created and initialized. If this is the first view tobe registered with MasterControl, then the BehaviorScheduler is alsocreated and initialized. If this is the first canvas registered for itsscreen, the Renderer for that screen is also created and initialized.

At this point, all threads and structures have been created andinitialized. The View, however, is still not active (i.e., itsstructures will not receive messages and its threads will not bescheduled by MasterControl). These will not occur until a Canvas3Dassociated with the view is activated. In one embodiment, threeconditions must be satisfied before a Canvas3D may be activated. First,a paint event must have been received on the Canvas3D. This is arequirement based on how AWT allocates underlying window systemresources for Canvas3Ds (this is described in greater detail below inthe Renderer section). Second, the Canvas3D must be in a running state.This is controlled directly by the Canvas3D.start/stopRenderer( )methods. The third and final condition is that the Canvas3D must bevisible on the screen. This is monitored by tracking various events onthe Canvas3D. To track events on the Canvas3D, an internal class(EventCatcher) implements all the appropriate listener interfaces forevents that the Canvas3D or BehaviorScheduler are to track. TheEventCatcher receives the events and then passes them onto theBehaviorScheduler. The EventCatcher also notifies the Canvas3D that itsstate has changed. If the state of any of the three conditions change,Canvas3D.evaluateActive( ) is called to re-evaluate the Canvas3D'sstate. If the Canvas3D's active state changes, it notifies the View thatit is associated with to evaluate its state—via View.evaluateActive( ).In one embodiment, there are two conditions that are met before it isactivated. First, it must be attached to a live ViewPlatform. Andsecond, one of the Views Canvas3Ds must be active. If the state of theView changes, it activates or deactivates itself.

View activation involves a several steps. First, a message is broadcastto the threads in the system that a new View has been activated. This isdone to ensure that the new View is registered with all interestedstructures. This message also makes the initial visibility and renderoperations happen on this View. Next, the View gets an id number if itdoesn't have one. The use of this id is discussed below. After receivingthe id number, the View checks to see if its VirtualUniverse has aprimary view. If it doesn't, then it has MasterControl select a newprimary view. Then, the View has its VirtualUniverse enable allcurrently enabled events(as selected by the BehaviorScheduler) on allthe Canvas3Ds associated with this View.

Note—ComponentEvents are always enabled for Canvas3Ds to ensureactivation tracking is always done. Finally, the View has MasterControlactivate it. At this point, MasterControl marks the Views RenderBin andSoundScheduler as active. If this is the only active View, MasterControlalso activates the BehaviorScheduler. At this point, the system is in anormal operating state.

System Flow

Since this implementation is based on message passing, there is no setsystem flow that occurs. However, to explain how the componentsinteroperate, an example application scenario can be used as an example.In this example, the application is HelloUniverse, a single cubespinning. From Java3D's point of view, this application consists of oneShape3D node with a TransformGroup above it that is changing. TheTransformGroup is being changed from a Behavior that gets triggered onceper frame. To see how this looks internally, one looks to MasterControlfirst.

Turning now to FIG. 8, one embodiment of the threads managed byMasterControl for the HelloUniverse example application is shown. Whilethe number of threads shown in the figure may seem high for such asimple application, only the ones with an “X” in the box will be run oneach iteration. Also note that each structure and update thread areconditionally created based on what is in the scene graph. First, tostart an interation, MasterControl takes a time snapshot. In otherwords, at this point in time, MasterControl decides which threads needto be run on this particular iteration. This decision is based on whatmessages have been sent to each thread. In the example shown in thefigure, two update threads are run. Since the TransformGroup is changingevery frame, the GeometryStructure and the RenderBin need to track theposition of the Shape3D node. Thus, their update threads get scheduledfor each iteration. In this case, both update threads update theirTransform3D values for the Shape3D node. Since the GeometryStructure andthe RenderBin are working on two different reference times, the valuesthey cache are different. This is accomplished with a new object calledthe CachedTransform. This object is explained in greater detail below inconnection with TransformGroup nodes. MasterControl waits for all updatethreads to finish before proceeding with this iteration. This ensuresthat the rest of the threads work with valid data without having totrack state updates.

The figure actually shows two thread lists. The first one containsupdate and “work” threads, while the second list has render threads.MasterControl keeps two lists so that it may process them in parallel,giving the render threads a higher priority. The render threads alwayswork off of the RenderBin structure, so there may be some constraints onwhat the RenderBin may do while processing messages. This is describedin greater detail in the RenderBin section below. In the HelloUniverseexample, the first Render thread will be scheduled first. It renders theRenderBin. At the same time, each update thread is allowed to run. Inthis example, that includes the TransformStructure and theGeometryStructure.

Next, the BehaviorScheduler is allowed to run, and finally the RenderBinupdate is allowed to run. During this time, if the Render threadfinishes, the render Swap thread is allowed to run. This completes aniteration of HelloUniverse.

Next, a brief description of what each thread does in this example isprovided. Since a TransformGroup is changing each frame, theTransformStructure needs to update the localToVworld values and boundsin virtual world coordinates for geometry objects in the system. Allupdate threads after the TransformStructure cannot be scheduled untilafter the TransformStructure update completes. This is because moststructures rely on its updated values.

The next structure to be updated is the GeometryStructure. Thisstructure maintains a spatial data structure of all geometry data in thescene. If one object moves, then this data structure is updated toreflect the new position of the object.

The BehaviorScheduler and RenderBin update may execute at the same time.The BehaviorScheduler will execute behaviors that have been triggeredsince the last cycle. In this case, it is the RotationInterpolator thatis spinning the cube.

For the RenderBin update, since the cube moved the RenderBin checks ifthe same lights and fog apply to this geometry. If the same ones apply,then it is done—which is the case here. The RenderBin update thread maynot actually modify the RenderBin. This is because the Renderer(s) areexecuting the RenderBin at the same time as the RenderBin update thread.If a change is needed, it is simply recorded and is deferred until theObjectUpdate time (described in greater detail below).

In parallel with this, the Renderer threads may also be running. Thefirst Renderer thread invocation is responsible for rendering allvisible objects into the Canvas3D. Once it has completed, the secondRenderer thread invocation will perform the buffer swap. After thebuffer swap has been completed, MasterControl may be configured tonotify the BehaviorScheduler that a frame has elapsed. That notificationtriggers the behavior again, and the process continues.

System Exit

One potential advantage of the Java memory model is that system exit andcleanup is relatively simple. If the application removes all referencesto its Java 3D objects, and if all Java 3D threads exit, then the Javagarbage collector will reclaim all of the Java resources that Java 3Dhas allocated. Unfortunately, in some implementations there is notsupport for notifying Java 3D when the application is finished with Java3D. Thus, an alternative mechanism may be used to ensure that Java 3Dthreads exit when they are not needed.

In one embodiment, this mechanism may be implemented in the existingaddNotify/removeNotify scheme. For example, as Canvas3Ds are removedfrom their containers, they may be configured to notify their Views.When a View is removed, it notifies MasterControl viaMasterControl.unregisterView( ). MasterControl then stops all thethreads associated with that View. If that was the last registered View,then MasterControl stops the VirtualUniverse based threads, and finallyitself. Since this removes all active Java 3D threads, when the user nolonger has any Java 3D references, it will be completely reclaimed bythe JVM (Java Virtual Machine). This completes the overview of the Java3D runtime system. Below, individual components that may be used toimplement the system and method described herein, their architecture,and the algorithms they use are described in greater detail.

MasterControl

MasterControl is the global controlling object in Java 3D. It is astatic object in the VirtualUniverse class, so there is only one in thesystem. Its main function is to perform user-based scheduling of allother threads. It may also implement a few of the API features.

Thread Creation and Destruction

In one embodiment, all schedulable threads in the system are subclassesof J3dThread. This class implements all initialization, communication,and destruction code for the threads. This gives MasterControl a commoninterface for creating, scheduling, and destroying threads.

There are two types of thread associations in the system, i.e., threadsassociated with a VirtualUniverse and threads associated with a View.Each will be discussed in turn. Regarding VirtualUniverse threads, theStructures for a VirtualUniverse are created when the VirtualUniverse iscreated. The threads associated with a VirtualUniverse only need to beinitialized when there is a registered view in:that VirtualUniverse. So,that becomes the triggering event for initalizing those threads. Whenthe first view of a VirtualUniverse is registered, MasterControlinitialized the threads for the VirtualUniverse. The structures that getcreated and initialize are the GeometryStructure, BehaviorStructure,SoundStructure, and RenderingEnvironmentStructure. Again, theRenderingAttributesStructure is created by MasterControl as one globalstructure. Each of these structures has an update thread that getsregistered with MasterControl. Along with these structures,MasterControl also created and initialized the BehaviorScheduler for theVirtualUniverse. Finally, if there is no MasterControlThread, thiscauses the MasterControlThread to be created and initialized.

For View-based threads, the triggering event is the registration of aView. When a View is registered, the threads for that View are createdand initialized. These threads include the SoundScheduler and the updatethread for the RenderBin. The InputDeviceScheduler for thePhysicalEnvironment of this View are also created and initialized (ifneeded). Also, each unique Screen3D associated with each Canvas3D of theView will have its Renderer thread initialized. Although the threadshave been created and initialized, they are not active yet. This happensonce a View becomes active. When a View becomes active, all the threadsassociated with it are activated. It is at this point that MasterControlconsiders them for scheduling. When a View gets deactivated, the threadsare simply marked as not active. They are not destroyed at this point.This allows for stopping the threads on a View without having to destroythem.

Thread destruction for View-based threads is triggered by theunregistering of a View. Since MasterControl is completely asynchronouswith View registration, some bookkeeping in needed. When a View isunregistered, MasterControl waits until a safe point in time beforedestroying the threads. Instead of destroying them immediately, itsimply puts them on a zombie thread list. Then, when theMasterControlThread looks for changes in the thread list, it willdestroy zombie threads by calling J3dThread.finish( ). Since a Viewcould possibly unregister and reregister itself before theMasterControlThread can clean the zombie list, it is desirable to haveall thread creation code first check if the thread to be created is onthe zombie list. Destruction of VirtualUniverse threads is triggered byremoval of the last View for a the VirtualUniverse. This is anasynchronous event as well, so the threads are also put on a zombie listto be purged by MasterControl at a safe time.

MasterControlThread

The MasterControl object is split into two parts to allow for Java 3D torelease associated resources when they are no longer needed. All thedata is held in the MasterControl object itself, while the controllingthread is encapsulated into the MasterControlThread (MCT). This allowsthe system to quickly create and destroy the controlling thread whilemaintaining system state. Using the flow of the MasterControlThread, thebulk of MasterControl can be explained. First, the MCT checks to see ifthere are any tasks (i.e., work) to be performed. The Boolean variableworkToDo is used to signal the MCT that there is pending work. If thereare no tasks to perform, then the MasterControlThread enters a waitstate until a task arrives. The work-causing action will notify the MCT.This allows Java 3D to refrain from consuming CPU resources when thereare no pending tasks to be performed.

WorkThreads List

Next, the MCT checks to see if any new threads have been added to thesystem. This is done in updateThreadLists( ). When a thread is added orremoved from the system, the MCT updates its list of schedulablethreads. When a thread change is needed, the Boolean variablethreadListsChanged is set. If this is the case, then updateThreadLists() recomputes the workThreads array of threads and cleans up any zombiethreads. Next, updateWorkThreads( ) makes thread scheduling decisions.As part of this process, updateWorkThreads( ) first calculate how manyentries are needed in the workThreads array. In one embodiment, theworkThreads array is two-dimensional. As noted above, there is an arrayof update/work threads and an array of render threads. The number ofentries for each is calculated as follows:

For the update/work list, the number of thread entries is:

The number of update threads, plus

The number of VirtualUniverses (one BehaviorScheduler for each), plus

For each View:

i. One SoundScheduler; and

ii. The number of unique PhysicalEnvironment's (InputDeviceScheduler)

This gives the total length of the update/work array.

For the render list, the number of thread entries is:

One render request thread, plus (For Offscreen and Immediate Mode)

For each View:

i. The number of Canvas3D's (1 Renderer per Canvas3D), plus

ii. The number of Screen3D's (1 Swap per Screen3D)

The workThreads array is an array of J3dThreadData objects. TheJ3dThreadData object encapsulates all the information needed to run athread for a single invocation. The data that J3dThreadData keepsincludes:

The thread reference, a J3dThread

A set of four time values (explained in the Time section)

A bitmask of options for this thread invocation

The arguments to be passed to the thread

Whether or not this thread needs to be run on this pass; and

Arguments used by the Renderer thread

The J3dThreadData object is used to allow a thread to exist in the listof workThreads more than once. An example of this is the Rendererthread, which may be run many times for a single MCT pass. Each threadis responsible for managing its list of J3dThreadData objects. In someembodiments, only the Renderer thread has more than one J3dThreadDataobject. It uses one J3dThreadData object for each View/Canvas3D pair forRendering and one J3dThreadData object for each View/Screen3D pair forSwapping.

After the workThreads array has been allocated, updateWorkThreads( ) maybe configured to fill in the array. As the J3dThreadData objects areadded to the array, they have their various fields filled in. There aresome thread run options that are used by the MCT to know how to managethe thread invocation. Some options are exclusive of other, while somemay be combined.

In one embodiment the list of options include:

J3dThreadData.CONT_THREAD: Other threads may run while this thread isrunning.

J3dThreadData.WAIT_THIS_THREAD: Wait until this thread is done beforeallowing any other threads to run.

J3dThreadData.WAIT_ALL_THREADS: Wait for all currently running threadsto complete before allowing any other threads to run.

One of the next two flags may be combined with the above flags.

J3dThreadData.START_TIMER: Start timing the frame associated with thegiven View.

J3dThreadData.STOP_TIMER: Stop timing the frame associated with thegiven view. Store the data in the View.

In filling the state array, the first thread in the array is theRenderingAttributeStructure update thread. It is first because there isonly one for the whole system. Next, each universe's TransformStructureupdate thread is added. These need to be run early so that other threadsmay use their updated values. This completes section one of the updatelist. All threads in this section may run in parallel, but the updatelist does not continue until they are done. The next section of threadsis a completion of the universe based update threads. So, for eachuniverse, and update thread is added for the GeometryStructure,BehaviorStructure, RenderingEnvironmentStructure, and SoundStructure.All threads in this section may run in parallel, but no more update/workthreads are run until they complete. This is because they will rely onthe updates to these structures. The final set of update/work threadsare a BehaviorScheduler for each universe, an InputDeviceScheduler foreach PhysicalEnvironment, and for each View a RenderBin update threadand a SoundScheduler. These threads may also run in parallel.

The second dimension of the workThreads array is used for renderthreads. MCT allows parallel rendering to Canvas3D's that are onseparate Screen3D's but that share the same View. To facilitate this,some data structures may be updated in the View when Canvas3D's areadded and removed from a View. They consist of two ArrayLists. Thefirst, the screenList, is a list of all Screen3Ds currently active. Thesecond, the canvasList, is a list of ArrayLists. Each ArrayList in thelist is a list of all Canvas3Ds on that Screen3D.

Turning now to FIG. 9, this structure is illustrated for three commoncases. The first case is most common, having one Canvas3D (308) on oneScreen3D (302). The second case has two Canvas3D's (308 and 320) on oneScreen3D (302). The third case is two Canvas3D's (308 and 320) on twoScreen3D's (302 and 316). The third case is one in which the system canrender to the two canvases in parallel. The canvasList (310) is cachedas a two dimensional array (310A-310B) of Canvas3D's, so it may beparsed quickly.

Returning to updateWorkThreads( ), the Renderers that need to bescheduled can be derived from this two dimensional array. Each entry inthe canvasList is an array of Canvas3D's for that Screen3D. The lengthof the canvasList array is the total number of Renderers that may run inparallel. The longest array in canvasList is the total number ofparallel Render groups that need to be scheduled. Since each Screen3Dmay have a different number of Canvas3D's on it, each parallel rendergroup may not be the same size. All Render threads in a parallel rendergroup, except the last one, have their thread options set toJ3dThreadData.CONT_THREAD. The last one in the render group has its flagset to J3dThreadData.WAIT_ALL_THREADS, because it will wait for everyonein its group to finish. All of these Renderer invocations have twothread arguments, the operation to perform (Renderer.RENDER) and theCanvas3D to render into.

The next set of threads to be added to the workThreads render array isthe Renderer threads that issue the swap buffers commands. There needsto be one thread invocation for each Screen3D in the View. This isdirectly gotten by iterating over canvasList again. All of theseRenderer thread invocations, except the last one, gets its thread optionset to J3dThreadData.CONT_THREAD since they can all run in parallel. Thelast Renderer gets its thread options flag set toJ3dThreadData.WAIT_ALL_THREADS and J3dThreadData.STOP_TIMER since itwill wait for all threads to finish and it will stop the View timer. Thearguments that each Renderer receives are the operations to perform(Renderer.SWAP), the View, and the list of Canvas3D's that are to beswapped. The last entry in the render array is a render request thread.It is used to process offscreen rendering and immediate mode requests.At this point, the workThreads array has been updated. OnceupdateWorkThreads( ) has completed, updateThreadLists( ) processes thelist of zombie threads and kills them by calling J3dThread.finish( ).Now, MasterControl has a completely updated set of threads to schedule.

Time

As mentioned above, in one embodiment there are four times associatedwith each thread. First, there is lastUpdateTime. This is the last timethat a message was sent to that thread. Each time a message is sent to athread, this value is updated. Next is updateTime. This is a snapshotvalue of lastUpdateTime. The snapshot time is taken at the beginning ofeach MCT iteration. Finally, there are lastUpdateReferenceTime andupdateReferenceTime. These times define the snapshot range of timevalues that are being processed on a given invocation of a thread. Theseare also taken at the beginning of each MCT iteration.

Returning to the flow of the MCT, once the workThreads list has beenchecked, MCT takes a time snapshot for the threads. This is done inupdateTimeValues( ). There are two time values that are saved on eachiteration, currentTime and lastTime. The variable currentTime isretrieved each time updateTimeValues( ) is called by calling getTime( ).The variable lastTime is the previous currentTime. For each snapshot,the time values between currentTime and lastTime define the current timerange.

After the two time values are updated, each workThread is examined. Eachthread's lastUpdateReferenceTime is set to lastTime, each thread'supdateReferenceTime is set to currentTime, and each thread's updateTimeis set to the thread's lastUpdateTime. If a thread's updateTime isgreater than its lastUpdateReferenceTime, then it is flagged as a threadthat needs to be run.

Running Threads

Once the time snapshot has happened, the MCT proceeds to run eachthread. It uses runMonitor( ) to let each thread run while adhering toits run flags and giving render threads a higher priority. When aJ3dThread is initialized, it immediately goes into its synchronizedrunMonitor( ) method and goes into a wait( ) state, waiting fornotification from the MCT. When it is time to run a thread, the MCT goesinto its own synchronized runMonitor( ) method and calls into thethread's runMonitor( ) method to notify( ) it and return.

At this point, the MCT can go into a number of states. If the thread runoptions indicate that it is to wait for this thread, the threadreference is stored, and the MCT keeps going into a wait( ) state untilthat thread's notify( ) indicates to the MCT that it is done. If thethread run options indicate that the MCT should wait for all threads tocomplete, the MCT repeatedly enters into a wait( ) state until allrunning threads are done. This is tracked by having a threadPendingcounter which represents the number of threads currently running. Ifneither of these options are set, the MCT may be configured to check tosee if it is out of CPU resources. It does this by checkingthreadPending against the cpuLimit. If they are equal, the MCT goes intoa wait( ) state until a thread completes. If none of these conditionsare true, then the MCT advances to the next thread. Once all the threadshave been processed, the MCT process the updateObject list, and thenreturns for another iteration.

Update Objects

When structures are processing their updates, it sometimes becomesnecessary to modify a part of the structure that the Renderers areusing. The structure cannot do the update when processing messages sincethe Renderers are most likely running at that time. In someimplementations an interface called ObjectUpdate may be defined toaddress this issue. The interface call may be an interface that consistsof a single updateObject( ) method. If an object finds that it needs tomake a modification to itself for which the Renderer depends, the objectimplements this interface. When the modification becomes necessary,object adds itself to MasterControl's object update list. WhenMasterControl decides that it is safe to make modifications to renderdependent structures, it calls the updateObject( ) method for eachobject on its update object list. This is how theRenderingAttributesStructure, TransformStructure, RenderBin, and othersprocess their render dependent modifications.

Frame Timer

One of the features that MasterControl implements is the View frametiming API. It does this by adding flags to the thread run options ofthe threads processed by the MCT. As the MCT iterates over each thread,it checks the thread's run flags. If the J3dThreadData.START_TIMER flagis set, the View is extracted from the thread arguments, the View'sframeNumber is incremented, and the frameStartTime is retrieved bycalling System.currentTimeMillis( ). Then the thread is allowed to run.If the J3dThreadData.STOP_TIMER flag is set for the thread, the threadis allowed to run, then the View is extracted from the threadsarguments, the stopTime for that View is recorded by callingSystem.currentTimeMillis( ), and the View.setFrameTimingValues( ) methodis called. This synchronized method takes the frameNumber, startTime,and stopTime values and updates the.currentFrameNumber,currentFrameStartTime, currentFrameDuration, and frameNumbers andframeStartTimes circular buffers. When an application retrieves any ofthese values with the View API's, they go through synchronized methodsto ensure that these values are stored and retrieved in an MT-SAFEmanner.

Messages

As noted above, messages may be used to communicate informationthroughout the system. MasterControl is the keeper and distributor ofmessages in the system. Whenever a message is needed, it is retrieved bycalling VirtualUniverse.mc.getMessage( ). This MasterControl methodfirst checks to see if the message freelist has any messages. If so, itrecycles one of those messages. If not, it creates a new one and returnsit. Once a component has a message, there are a number of fields thatneed to be filled in before it is sent into the system. The first fieldto be filled in is the universe. Next, the type of the message is filledin. All message types are found in the J3dMessage class. Then, thethread's bitmask is filled in. This is a bitmask of all thread typesthat need to be sent this message. All the possible thread types can befound in the J3dThread class. Finally, any arguments for the messageneed to be filled in. The maximum number of arguments is currently 5,but that number is arbitrary. Once, all the fields are complete, themessage gets sent into the system by callingVirtualUniverse.mc.processMessage( ). There are two main types ofmessages that can be processed. There are messages that get sent tostructures as well as notify work threads. And, there are messages thatare only intended to notify a thread that it needs to run. If thislatter case is all that is needed, the component may simply callVirtualUniverse.mc.sendRunMessage( ) to notify the threads specified inthe arguments.

Sending Messages

When a message is sent to VirtualUniverse.mc.processMessage( ), it goesthrough the following steps. First, the time field of the message isfilled in by getting a new time value via getTime( ). Next, each workthread that the message is destined to has its lastUpdateTime value setto the message's new time value. Then, any structure that this messageis meant for is sent the message by calling J3dStructure.addMessage( ).Finally, MasterControl is notified that there is work to do.

Consuming Messages

Messages are sent to structures by MasterControl through itsprocessMessages( ) method. It is the responsibility of the structureupdate methods to retrieve the messages. When a thread is notified torun by MasterControl, it receives two time values, lastUpdateTime andreferenceTime. The time value lastUpdateTime is the last time value whena message was sent to this structure. It also gets a referenceTime,which is the reference time that the thread is to work in. Forstructures, this means that the update thread needs to consume allmessages greater than or equal to lastUpdateTime but not greater thanreferenceTime.

When the structures processMessages( ) method gets called, the structurecalls getMessages( ) with the time range. This method returns allmessages falling into that time range. A single message can go to manystructures, so each message has a reference count. Each time the messageis added to a structures message queue, its reference count isincremented. The last thing each structures processMessages( ) methodperforms is to call J3dMessage.decRefcount( ). When the reference countgoes to 0, all its fields are nulled out and it gets put on theMasterControl message freelist.

Primary Views

MasterControl is also responsible for is assigning primary views foreach VirtualUniverse. There are two cases when MasterControl can becalled upon to do this. When a View becomes active, it checks to see ifits VirtualUniverse has a primary View. If it does not, it callsVirtualUniverse.mc.assignNewPrimaryView( ). Also, when a View isdeactivated, if it is the primary View for its VirtualUniverse, it callsVirtualUniverse.mc.assignNewPrimaryView( ). If the VirtualUniversepassed in has a primary view, it is one that is no longer active, so itsets that Views primaryView flag to false. Then it iterates over allactive Views looking for one in the given VirtualUniverse. It stops whenit finds the first one. If one is found, the View's primaryView flag isset to true and the VirtualUniverse's primary view is set to the onefound. If one is not found, the VirtualUniverse's primary view is set tonull.

Although the embodiments above have been described in considerabledetail, other versions are possible. Numerous variations andmodifications will become apparent to those skilled in the art once theabove disclosure is fully appreciated. It is intended that the followingclaims be interpreted to embrace all such variations and modifications.Note the headings used herein are for organizational purposes only andare not meant to limit the description provided herein or the claimsattached hereto.

What is claimed is:
 1. A computer program embodied on an electronicmedium, wherein the computer software program comprises a plurality ofinstructions configured to perform the following: receive a scene graph,wherein the scene graph comprises information representing a pluralityof three-dimensional objects, wherein the information includes:appearance data, geometry data, and environmental data; and traverse thescene graph to generate a plurality of structures and threadscorresponding to the scene graphs, wherein each structure comprises anobject that manages selected data from the scene graph, and wherein theplurality of threads are executable to render one or more framescorresponding to the scene graph.
 2. The computer program of claim 1,wherein the threads are configured to generate messages to specify statechanges.
 3. The computer program of claim 2, wherein the messages can bemulticast to multiple structures or unicast to a single structure. 4.The computer program of claim 1, wherein each structure has acorresponding update thread configured to update the structure.
 5. Thecomputer program of claim 1, wherein the scene graph includes behaviordata for the three-dimensional objects.
 6. The computer program of claim1, wherein the environmental data includes lighting and fog information.7. The computer program of claim 1, wherein one structure is a renderbin configured to receive messages that store references to particulargeometry data that is to be rendered in the render bin.
 8. The computerprogram of claim 7, wherein the render bin has one or more renderthreads associated with it, wherein each render thread is configured torender the geometry data.
 9. The computer program of claim 1, whereinthe program is configured to have each structure optimize thestructure's data from the scene graph.
 10. The computer program of claim1, wherein the program is configured to optimize the structure's data bystripifying geometry data.
 11. The computer program of claim 1, whereinthe program is configured to optimize the structure's data by splittingnodes.
 12. The computer program of claim 1, wherein the program isconfigured to optimize the structures by flattening the scene graph. 13.The computer program of claim 1, wherein one of the structures is abounding box.
 14. The computer program of claim 2, wherein the messagesinclude a time stamp.
 15. The computer program of claim 14, wherein thetime stamp is a change count.
 16. The computer program of claim 2,wherein the messages include an event stamp.
 17. The computer program ofclaim 2, wherein the messages are utilized to allow parallel processingof individual threads.
 18. A method comprising: generating a scenegraph, wherein the scene graph comprises information representing aplurality of three-dimensional objects; and traversing the scene graphto generate a parallel set of structures and threads corresponding tothe scene graph, wherein each structure comprises an object that managesselected data from the scene graph, and wherein each thread isexecutable to render one or more frames corresponding to the scenegraph.
 19. The method of claim 18, wherein the selected data includes:geometry data, transform data, lighting data, object behavior data,rendering attribute data, rendering environment data, and view data. 20.The method of claim 18, wherein the threads are configured to generatemessages to specify state changes.
 21. The method of claim 20, whereinthe messages can be multicast to multiple structures or unicast to asingle structure.
 22. The method of claim 18, wherein each structure hasa corresponding update thread configured to update the structure. 23.The method of claim 18, wherein the scene graph includes behavior datafor the three-dimensional objects.
 24. The method of claim 18, whereinthe selected data includes lighting and fog information.
 25. The methodof claim 18, wherein one structure is a render bin configured to receivemessages that store references to particular geometry data that is to berendered in the render bin.
 26. A method comprising: receiving a scenegraph; and generating a parallel set of structures and threadscorresponding to the scene graph, wherein each structure comprises anobject that manages selected data from the scene graph, and wherein afirst subset of the threads are executable to update the structuresbased on changes to the objects, and wherein a second subset of thethreads are executable to render an image based on the structureswithout repeatedly traversing the scene graph.
 27. A method comprising:generating a scene graph, wherein said generating comprises adding nodesto a hierarchy, wherein the nodes include information defining one ormore three-dimensional graphical objects that are part of athree-dimensional world; and creating a parallel set of structures andthreads corresponding to the scene graph, wherein said creating isperformed in connection with said adding, wherein for each node added tothe hierarchy, one corresponding data structure or thread is generated,and wherein a first subset of the generated threads are executable toupdate one or more of the generated data structures based on changes tothe objects, and wherein a second subset of the generated threads areexecutable to render an image based on the generated data structures.28. The method of claim 27, wherein the selected data includes: geometrydata, transform data, lighting data, geometry data, object behaviordata, rendering attribute data, rendering without repeatedly traversingthe scene graph.